import { axios } from '@/utils/ask'

// 获取博客列表
export const getBlogList = (data) => {
  return axios.request({
    url: '/blog/blogInfo/blogList',
    data: data,
    method: 'post'
  })
}

// 获取博客类型列表
export const getTypeList = () => {
  return axios.request({
    url: '/blog/blogType/list',
    method: 'post'
  })
}

// 获取博客标签列表
export const getTagList = () => {
  return axios.request({
    url: '/blog/blogTag/list',
    method: 'post'
  })
}

// 获取博客类型列表
export const getBlogTypes = () => {
  return new Promise((resolve, reject) => {
    axios.request({
      url: '/blog/blogType/typeList',
      method: 'post'
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 根据类型获取博客标题列表
export const getBlogsByType = (params) => {
  return new Promise((resolve, reject) => {
    axios.request({
      url: '/blog/blogInfo/getBlogsByType',
      data: params,
      method: 'post'
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 获取博客标签列表
export const getBlogTags = () => {
  return new Promise((resolve, reject) => {
    axios.request({
      url: '/blog/blogTag/list',
      method: 'post'
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 新建一篇文章
export const addBlog = (params) => {
  return new Promise((resolve, reject) => {
    axios.request({
      url: '/blog/blogInfo/add',
      data: params,
      method: 'post'
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 添加博客类型
export const addBlogType = (params) => {
  return new Promise((resolve, reject) => {
    axios.request({
      url: '/blog/blogType/add',
      data: params,
      method: 'post'
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}
// 添加博客标签
export const addBlogTag = (params) => {
  return new Promise((resolve, reject) => {
    axios.request({
      url: '/blog/blogTag/add',
      data: params,
      method: 'post'
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 更新博客
export const updateBlog = (params) => {
  return new Promise((resolve, reject) => {
    axios.request({
      url: '/blog/blogInfo/update',
      data: params,
      method: 'post'
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 更新博客类型
export const updateBlogType = (params) => {
  return new Promise((resolve, reject) => {
    axios.request({
      url: '/blog/blogType/edit',
      data: params,
      method: 'post'
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 点赞
export const likeOrNot = (params) => {
  return new Promise((resolve, reject) => {
    axios.request({
      url: '/blog/comment/likeOrNot',
      data: params,
      method: 'post'
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 删除博客类型
export const deleteBlogType = (params) => {
  return new Promise((resolve, reject) => {
    axios.request({
      url: '/blog/blogType/delete',
      data: params,
      method: 'post'
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 删除博客内容
export const deleteBlog = (params) => {
  return new Promise((resolve, reject) => {
    axios.request({
      url: '/blog/blogInfo/delete',
      data: params,
      method: 'post'
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}
// 获取博客标签列表
export const doComments = (params) => {
  return new Promise((resolve, reject) => {
    axios.request({
      url: '/blog/comment/doComment',
      data: params,
      method: 'post'
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 获取评论列表
export const getCommentList = (params) => {
  return new Promise((resolve, reject) => {
    axios.request({
      url: '/blog/comment/getCommentByBlogId',
      data: params,
      method: 'post'
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 获取 推荐博客列表
export const getRecommendedArticle = (params) => {
  return new Promise((resolve, reject) => {
    axios.request({
      url: '/blog/blogInfo/getRecommendedArticle',
      data: params,
      method: 'post'
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 回复评论
export const replyComments = (params) => {
  return new Promise((resolve, reject) => {
    axios.request({
      url: '/blog/comment/reply',
      data: params,
      method: 'post'
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

// 将图片上传到服务器
export const uploadImage = (formdata) => {
  return new Promise((resolve, reject) => {
    axios.request({
      url: '/blog/blogInfo/uploadImage',
      data: formdata,
      method: 'post',
      headers: { 'Content-Type': 'multipart/form-data' }
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

